/**
 *====================================================
 * 文件名称: SupervisionEndallServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.RandomUtil;
import com.yuexunit.finance.project.SettingConstants;
import com.yuexunit.finance.project.entity.SupervisionEndallEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: SupervisionEndallServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(SupervisionEndallService.class)
public class SupervisionEndallServiceImpl implements SupervisionEndallService {

	@Override
	public Long createSupervisionEndall(SupervisionEndallEntity entity) {
		entity.setEndallNumber(SettingConstants.PRE_NUMBER_SUPERVISION_ENDALL + RandomUtil.generateTimeNumber());
		entity.setCreateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getSupervisionEndallId();
	}

	@Override
	public SupervisionEndallEntity inquireSupervisionEndallEntity(Long supervisionEndallId) {
		return PersistUtil.get(SupervisionEndallEntity.class, supervisionEndallId);
	}

	@Override
	public SupervisionEndallEntity inquireFinanceSupervisionEndallEntity(Long financeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(SupervisionEndallEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		List<SupervisionEndallEntity> list = PersistUtil.get(criteria);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

}
